package com.qinghe.pro.controller.front;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.qinghe.pro.Constants;
import com.qinghe.pro.service.article.ArticleService;
import com.qinghe.pro.service.article.ColumnService;
import com.qinghe.pro.shiro.ShiroUser;
import com.qinghe.utils.SecurityUtils;

@Controller
@RequestMapping("/layout")
public class LayoutController {

	@Autowired
	@Qualifier("columnServiceImpl")
	private ColumnService columnService;

	@Autowired
	@Qualifier("articleServiceImpl")
	private ArticleService articleService;

	private static final String HEADER = "/layout/header";
	private static final String FOOTER = "/layout/footer";
	private static final String RIGHT = "/layout/right";

	/**
	 * 首页顶部菜单
	 */
	@RequestMapping(value = "/header", method = { RequestMethod.GET, RequestMethod.POST })
	public String header(Integer columnId, String tag, Map<String, Object> map) {
		ShiroUser shiroUser = SecurityUtils.getShiroUser();
        if (shiroUser != null) {
        	map.put("user", shiroUser.getUser());
        }
        map.put("menuModule", columnService.getTree());
        map.put("columnId", columnId);
        map.put("tag", tag);
		return HEADER;
	}

	/**
	 * 首页底部菜单
	 */
	@RequestMapping(value = "/footer", method = { RequestMethod.GET, RequestMethod.POST })
	public String footer() {
		return FOOTER;
	}

	/**
	 * 右侧新闻-》推荐阅读
	 */
	@RequestMapping(value = "/right", method = { RequestMethod.GET, RequestMethod.POST })
	public String right(Map<String, Object> map) {
		// 右侧新闻栏目
		map.put("articleList", articleService.findByType(Constants.COLUMN_TYPE_RIGHT, 10));
		return RIGHT;
	}

}
